home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12739 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  50 lines

  1. Newsgroups: comp.lang.c,comp.lang.perl
  2. Path: news.eng.convex.com!arco!usenet
  3. From: "James W. Bielak" <bielak@arco.com>
  4. Subject: Re: Random File Access - I don't get it
  5. X-Nntp-Posting-Host: 130.201.20.122
  6. Content-Type: text/plain; charset=us-ascii
  7. Message-ID: <Dp8nq5.4Eo@news.arco.com>
  8. Sender: usenet@news.arco.com
  9. Content-Transfer-Encoding: 7bit
  10. Organization: ARCO
  11. References: <3160DE1E.495C@teleport.com>
  12. Mime-Version: 1.0
  13. Date: Tue, 2 Apr 1996 14:18:05 GMT
  14. X-Mailer: Mozilla 1.1 (X11; U; SunOS 4.1.3_U1 sun4c)
  15. X-Url: news:3160DE1E.495C@teleport.com
  16.  
  17. Scott Kinard <kinards@teleport.com> wrote:
  18. >Greetings,
  19. >
  20. >  As I was coding a simple program to randomly read lines from a text file it occurred 
  21. >to me something was amiss. This is probably some fundamental oversight on my part, but 
  22. >some illumination would be helpful...
  23. >
  24. >  Suppose I have two files, one contains text (1 line of random length text per 
  25. >'record') and another which is my index into the text file, which contains the starting 
  26. >and ending byte positions in the text file for each 'record'. Now the question..
  27. >
  28. >Suppose the text file has 2,000,000 entries. Now, what's the difference in reading 
  29. >1,000,000 lines from the index file to find the starting and ending byte positions in 
  30. >the text file for record 1,000,000, and then seeking these in the text file, rather than 
  31. >just reading 1,000,000 times from the text file to get the same 'record' in the first 
  32. >place?
  33. >
  34. >-Scott
  35.  
  36. Which of these do you think will take longer:
  37.  
  38. open index file
  39. seek offset (1,000,000 * record size)
  40. open text file
  41. seek record offset
  42.  
  43. or...
  44.  
  45. for (i=0;i<1000000;1++)
  46.     read a buffer
  47.  
  48. jwb
  49.  
  50.